package com.zengzhi.mydesignmode.observermode.javaobservermode;

import java.util.Observable;
import java.util.Observer;

/**
 * @author xiejiawei
 * @Date 2021-08-16
 * @Time 21:53
 * 当前天气状态的布告版
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {

    Observable observable;
    private float temperature;
    private float humidity;
    private float pressure;
    CurrentConditionsDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }
    /**
     * 显示的方法
     */
    @Override
    public void disPlay() {
        System.out.println("Current Conditions:"  + temperature
        + "F degrees and" + humidity +"% humidity:"+pressure);
    }

    /**
     * 更新的接口
     */
    @Override
    public void update(Observable obs ,Object object) {
        if(obs instanceof WeatherData){
            WeatherData weatherData  = (WeatherData) obs;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            this.pressure = weatherData.getPressure();
            disPlay();
        }
    }
}
